const express = require("express");
const router = express.Router();
const Mock = require("mockjs");
const path = require("path");
const fs = require("fs");

// nextjs 测试 接口
router.get("/", (req, res) => {
  const mockData = Mock.mock({
    "list|10": [
      {
        id: "@id",
        title: "@ctitle(5, 10)",
        content: "@cparagraph(2, 5)",
        time: '@datetime("yyyy-MM-dd HH:mm:ss")',
        author: "@cname",
      }
    ],
  });
  // console.log(mockData);
  res.status(200).send({
    code: 201,
    data: {
      mock: mockData.list,
    },
    message: "响应成功~~~",
  });
});

// 新闻接口调试
router.get("/news", (req, res) => {
  console.log("/news start");

  console.log("query", req.query);

  res.status(200).send({
    code: 200,
    data: {
      id: req.query.id,
      news: "新闻首页",
    },
    message: "响应成功~~~",
  });
});

module.exports = router;
